﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Demo.Framework.DataStructure.Problems.AthleteTower
{
    class Athlete : IComparable
    {
        public int Mass { get; set; }
        public int Strength { get; set; }
        private Athlete _athleteOnTop;

        public Athlete(int mass, int strength)
        {
            Mass = mass;
            Strength = strength;
        }

        public void PutAthleteOnTop(Athlete athlete)
        {
            _athleteOnTop = athlete;
        }

        public int GetNetWeightExerted()
        {
            if (_athleteOnTop == null)
	        {
                return this.Mass;		 
	        }
            else
            {
                return this.Mass + _athleteOnTop.Mass;
            }            
        }

        public bool TestStrength()
        {
            return Strength >= GetNetWeightExerted();
        }

        public int CompareTo(object obj)
        {
            Athlete otherAthlete = obj as Athlete;
            if (otherAthlete.Mass != this.Mass)
            {
                return (otherAthlete.Mass.CompareTo(this.Mass)) *-1;
            }
            else
            {
                return (otherAthlete.Strength.CompareTo(this.Strength)) *-1;
            }            
        }
    }
}
